/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.cosmact.vxml.model.impl;

import org.cosmact.vxml.model.Dialog;
import org.cosmact.vxml.model.DialogConnection;
import org.cosmact.vxml.model.DialogConnectionType;
import org.cosmact.vxml.model.ModelPackage;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Dialog Connection</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogConnectionImpl#getSource <em>Source</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogConnectionImpl#getTarget <em>Target</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogConnectionImpl#getConnectionType <em>Connection Type</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogConnectionImpl#isIsConnect <em>Is Connect</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DialogConnectionImpl extends EObjectImpl implements DialogConnection {
	/**
         * The cached value of the '{@link #getSource() <em>Source</em>}' reference.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getSource()
         * @generated
         * @ordered
         */
	protected Dialog source;

	/**
         * The cached value of the '{@link #getTarget() <em>Target</em>}' reference.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getTarget()
         * @generated
         * @ordered
         */
	protected Dialog target;

	/**
         * The cached value of the '{@link #getConnectionType() <em>Connection Type</em>}' reference.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getConnectionType()
         * @generated
         * @ordered
         */
	protected DialogConnectionType connectionType;

	/**
         * The default value of the '{@link #isIsConnect() <em>Is Connect</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #isIsConnect()
         * @generated
         * @ordered
         */
	protected static final boolean IS_CONNECT_EDEFAULT = false;

	/**
         * The cached value of the '{@link #isIsConnect() <em>Is Connect</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #isIsConnect()
         * @generated
         * @ordered
         */
	protected boolean isConnect = IS_CONNECT_EDEFAULT;

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	protected DialogConnectionImpl() {
                super();
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	protected EClass eStaticClass() {
                return ModelPackage.Literals.DIALOG_CONNECTION;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Dialog getSource() {
                if (source != null && source.eIsProxy()) {
                        InternalEObject oldSource = (InternalEObject)source;
                        source = (Dialog)eResolveProxy(oldSource);
                        if (source != oldSource) {
                                if (eNotificationRequired())
                                        eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelPackage.DIALOG_CONNECTION__SOURCE, oldSource, source));
                        }
                }
                return source;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Dialog basicGetSource() {
                return source;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setSource(Dialog newSource) {
                Dialog oldSource = source;
                source = newSource;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__SOURCE, oldSource, source));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Dialog getTarget() {
                if (target != null && target.eIsProxy()) {
                        InternalEObject oldTarget = (InternalEObject)target;
                        target = (Dialog)eResolveProxy(oldTarget);
                        if (target != oldTarget) {
                                if (eNotificationRequired())
                                        eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelPackage.DIALOG_CONNECTION__TARGET, oldTarget, target));
                        }
                }
                return target;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Dialog basicGetTarget() {
                return target;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setTarget(Dialog newTarget) {
                Dialog oldTarget = target;
                target = newTarget;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__TARGET, oldTarget, target));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public DialogConnectionType getConnectionType() {
                if (connectionType != null && connectionType.eIsProxy()) {
                        InternalEObject oldConnectionType = (InternalEObject)connectionType;
                        connectionType = (DialogConnectionType)eResolveProxy(oldConnectionType);
                        if (connectionType != oldConnectionType) {
                                if (eNotificationRequired())
                                        eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE, oldConnectionType, connectionType));
                        }
                }
                return connectionType;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public DialogConnectionType basicGetConnectionType() {
                return connectionType;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setConnectionType(DialogConnectionType newConnectionType) {
                DialogConnectionType oldConnectionType = connectionType;
                connectionType = newConnectionType;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE, oldConnectionType, connectionType));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public boolean isIsConnect() {
                return isConnect;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setIsConnect(boolean newIsConnect) {
                boolean oldIsConnect = isConnect;
                isConnect = newIsConnect;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__IS_CONNECT, oldIsConnect, isConnect));
        }

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void reconnect(Dialog source, Dialog target) {
		if (source == null || target == null || source == target) {
			throw new IllegalArgumentException();
		}
		disconnect();
		this.source = source;
		this.target = target;
		reconnect();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void disconnect() {
		if (isConnect) {
			source.removeConnection(this);
			target.removeConnection(this);
			isConnect = false;
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void reconnect() {
		if (!isConnect) {
			source.addConnection(this);
			target.addConnection(this);
			isConnect = true;
		}
	}

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
                switch (featureID) {
                        case ModelPackage.DIALOG_CONNECTION__SOURCE:
                                if (resolve) return getSource();
                                return basicGetSource();
                        case ModelPackage.DIALOG_CONNECTION__TARGET:
                                if (resolve) return getTarget();
                                return basicGetTarget();
                        case ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE:
                                if (resolve) return getConnectionType();
                                return basicGetConnectionType();
                        case ModelPackage.DIALOG_CONNECTION__IS_CONNECT:
                                return isIsConnect() ? Boolean.TRUE : Boolean.FALSE;
                }
                return super.eGet(featureID, resolve, coreType);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public void eSet(int featureID, Object newValue) {
                switch (featureID) {
                        case ModelPackage.DIALOG_CONNECTION__SOURCE:
                                setSource((Dialog)newValue);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__TARGET:
                                setTarget((Dialog)newValue);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE:
                                setConnectionType((DialogConnectionType)newValue);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__IS_CONNECT:
                                setIsConnect(((Boolean)newValue).booleanValue());
                                return;
                }
                super.eSet(featureID, newValue);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public void eUnset(int featureID) {
                switch (featureID) {
                        case ModelPackage.DIALOG_CONNECTION__SOURCE:
                                setSource((Dialog)null);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__TARGET:
                                setTarget((Dialog)null);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE:
                                setConnectionType((DialogConnectionType)null);
                                return;
                        case ModelPackage.DIALOG_CONNECTION__IS_CONNECT:
                                setIsConnect(IS_CONNECT_EDEFAULT);
                                return;
                }
                super.eUnset(featureID);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public boolean eIsSet(int featureID) {
                switch (featureID) {
                        case ModelPackage.DIALOG_CONNECTION__SOURCE:
                                return source != null;
                        case ModelPackage.DIALOG_CONNECTION__TARGET:
                                return target != null;
                        case ModelPackage.DIALOG_CONNECTION__CONNECTION_TYPE:
                                return connectionType != null;
                        case ModelPackage.DIALOG_CONNECTION__IS_CONNECT:
                                return isConnect != IS_CONNECT_EDEFAULT;
                }
                return super.eIsSet(featureID);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public String toString() {
                if (eIsProxy()) return super.toString();

                StringBuffer result = new StringBuffer(super.toString());
                result.append(" (isConnect: ");
                result.append(isConnect);
                result.append(')');
                return result.toString();
        }

} //DialogConnectionImpl
